﻿

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 高斯模糊
    /// </summary>
    [Filter("高斯模糊",FilterType.Algorithm)]
    public class AlgorithmGaussianBlur:FilterBase
    {
        /// <summary>
        /// 大小
        /// </summary>
        [InputParameter("粒子大小")]
        public CVSize KernalSize { get; set; }=new CVSize() { };
        /// <summary>
        /// X
        /// </summary>
        [InputParameter("X偏移")] 
        public double SigmaX { get; set; }
        /// <summary>
        /// Y
        /// </summary>
        [InputParameter("Y偏移")]
        public double SigmaY { get; set; }
        /// <summary>
        /// 边框样式
        /// </summary>
        [InputParameter("边框样式")]
        public BorderTypes BorderType { get; set; } = BorderTypes.Default;

        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
            Mat mat1 = new Mat();
            var inf = (Size)KernalSize;
            if (inf.Height%2!=1)
            {
                inf.Height += 1;
            }
            if (inf.Width % 2 != 1)
            {
                inf.Width += 1;
            }
            Cv2.GaussianBlur(mat, mat1, inf, SigmaX,SigmaY, BorderType);
            return ResultData<Mat>.Accept(TextResource.blur_complete, mat1);

        }
    }
}
